<template>
  <view class="content">
    <mescroll-uni
      ref="mescrollRef"
      @init="mescrollInit"
      @up="upCallback"
      :up="upOption"
      :down="{ use: false }"
    >
      <view class="section-0">
        <view class="section-body">
          <view class="list">
            <view class="wrapper">
              <view class="form-item">
                <text class="label">实际开工时间</text>
                <view class="value">
                  <view class="date" @click="showStart = true">
                    <view class="input-body">{{ start }}</view>
                    <view class="iconfont icon-rili"></view>
                  </view>
                </view>
              </view>
            </view>
            <!-- <view class="title">关键管控节点：</view> -->
            <!-- <view class="contentList">
              <view class="row">
                <text class="text">1.第一次工地例会、安委会</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    ref="checks"
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name="（管控卡） "
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
              <view class="row">
                <text class="text">2.设计交底及施工图会检</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name=" （管控卡）"
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
              <view class="row">
                <text class="text">3.监理项目部标准化配置达标检查</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name="（自己打勾）"
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
              <view class="row">
                <text class="text">4.开工报审表</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name="（PC上传）"
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
              <view class="row">
                <text class="text">5.批准开工15日之内报备材料</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name="（手动）"
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
              <view class="row">
                <text class="text">6.三级及以上风险清册会审</text>
                <u-checkbox-group
                  v-model="checkboxValue1"
                  placement="column"
                  @change="checkboxChange"
                  class="change"
                >
                  <u-checkbox
                    shape="circle"
                    :customStyle="{ marginBottom: '8px' }"
                    name="（管控卡）"
                  >
                  </u-checkbox>
                </u-checkbox-group>
              </view>
            </view> -->
          </view>
          <u-datetime-picker
            :show="showStart"
            v-model="startStamp"
            closeOnClickOverlay
            mode="date"
            @confirm="confirmStart"
            @cancel="showStart = false"
            @close="showStart = false"
          ></u-datetime-picker>
        </view>
      </view>
      <view class="preservation">
        <u-button
          class="preservabtn"
          type="primary"
          text="保存"
          @click="submit"
        ></u-button>
      </view>
    </mescroll-uni>
  </view>
</template>

<script>
import { getStartTime, changeStartTime } from "@/api/project.js";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      start: "",
      startStamp: Number(new Date()),
      showStart: false,
      list: [],

      checkboxValue1: [],
      checkboxValue2: [],
      checkboxValue3: [],
      checkboxValue4: [],
      checkboxValue5: [],
      checkboxValue6: [],
      checkboxList1: [
        {
          name: "（管控卡）",
          disabled: false,
        },
      ],
      upOption: {
        textNoMore: "-- 没有更多了 --",
      },
    };
  },
  // onReady() {
  //   console.log(this.$refs.checks.isChecked);
  // },

  computed: {
    ...mapGetters({
      curProject: "system/getCurProject",
    }),
  },

  methods: {
    checkboxChange(n) {
      console.log(n);
      // console.log(this.$refs.checks.isChecked);
    },

    mescrollInit(mescroll) {
      this.mescroll = mescroll;
    },

    async upCallback() {
      const data = await getStartTime({
        project_id: this.curProject.id,
      });

      if (data.data.data.kg_time_real == null) {
        console.log(111);
        this.start = "";
        this.mescroll.endErr();
      } else if (data.data.code == 1) {
        console.log(222);
        this.start = data.data.data.kg_time_real.substring(0, 10);
        this.mescroll.endErr();
      } else {
        this.mescroll.endErr();
      }
    },
    confirmStart(val) {
      const timeStamp = val.value;
      this.start = this.formatDate(timeStamp);
      this.showStart = false;
    },
    formatDate(timeStamp) {
      const date = new Date(timeStamp);
      const Y = date.getFullYear() + "-";
      const M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      const D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      const h = date.getHours() + ":";
      const m = date.getMinutes() + ":";
      const s = date.getSeconds();
      return Y + M + D;
    },

    //提交时间
    async submit() {
      console.log(this.start);
      const data = await changeStartTime({
        project_id: this.curProject.id,
        kg_time_real: this.start,
      });
      if (data.data.code == 1) {
        console.log(data.data);
        uni.showToast({
          title: "保存成功",
          duration: 1000,
          icon: "success",
        });
        uni.hideLoading();
      } else {
        console.log(data.data);
        uni.showToast({
          title: "保存失败，请重试",
          duration: 1000,
          icon: "error",
        });
        uni.hideLoading();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
  border-radius: 35rpx;
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
  box-sizing: border-box;
  box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
  padding: 28rpx 40rpx;
  padding-top: 15rpx;
  margin-bottom: 40rpx;
  font-size: 27rpx;
}

.section-0 {
  width: 100%;
  position: relative;
  top: -50rpx;
  z-index: 10;
  background-color: #2e5efe;
  margin-top: 17rpx;
  .section-body {
    width: 100%;
    height: 100%;
    margin-top: 50rpx;
    border-top-left-radius: 50rpx;
    border-top-right-radius: 50rpx;
    background-color: #fff;
    overflow: hidden;
    padding-top: 46rpx;
    .label {
      margin-left: -32rpx;
      margin-top: 21rpx;
      color: #000 !important;
      font-weight: bolder;
    }
    .input-body {
      height: 55.6rpx;
      width: 501rpx;
      border: 1px solid #1534ce;
      border-radius: 28.8rpx;
      margin-top: 13.5rpx;
    }
    .list {
      width: 670rpx;
      box-sizing: border-box;
      margin-left: 40rpx;
      .form-item {
        width: 662rpx;
        height: 48rpx;
        border-radius: 20rpx;
        margin: 0 auto;
        margin-bottom: 25rpx;

        @include clear();
        .label {
          float: left;
          width: 209rpx;
          height: 48rpx;
          text-align: center;
          line-height: 44rpx;
          font-size: 26rpx;
          font-stretch: normal;
          letter-spacing: 0rpx;
          margin-left: -32rpx;
          margin-top: 21rpx;
          color: #000 !important;
          font-weight: bolder;
        }
        .icon-rili {
          margin-left: 551rpx;
          margin-top: -44rpx;
          font-size: 33rpx;
          color: #1534ce;
        }
        .input-body {
          box-sizing: border-box;
          padding: 0 !important;
          padding-left: 30rpx !important;
          padding-right: 30rpx !important;
          font-size: 26rpx;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0rpx;
          text-align: center;
          font-size: 28rpx;
          color: #1534ce;
          line-height: 55.6rpx;
          height: 55.6rpx !important;
          width: 428rpx !important;
          border: 1px solid #1534ce !important;
          border-radius: 28.8rpx !important;
          margin-top: 13.5rpx !important;
          margin-left: 172rpx;
        }
        .input-placeholder {
          font-size: 26rpx;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0rpx;
          color: rgba(0, 0, 0, 0.5);
        }
      }
      .title {
        padding-bottom: 29rpx;
        border-bottom: 2rpx solid #ecf3f6;
      }
      .contentList {
        .row {
          font-size: 26rpx;
          display: flex;
          justify-content: space-between;
          border-bottom: 2rpx solid #ecf3f6;
          padding-bottom: 19rpx;
          padding-top: 19rpx;
          // .text {
          //   flex: 0.65;
          // }
          // .change {
          //   flex: 0.35;
          // }
        }
      }
    }
  }
}
.preservation {
  width: 100%;
  height: 115rpx;
  position: fixed;
  bottom: 0rpx;
  right: 0;
  padding-top: 21rpx;
  box-shadow: 0 0 10rpx 10rpx rgba(#bcbcb5, 0.17);
  .preservabtn {
    width: 75%;
    margin: auto;
  }
}
</style>
